<template>
  <div class="container-xl bg-white">
    <div class="row">
      <div class="col p-40">
        <div v-html="data.context" class="editor-content-view"></div>
      </div>
    </div>
    <div v-if="data.ID">
      <el-button @click="click(false)">拒绝</el-button>
      <el-button type="success" @click="click(true)">加入</el-button>
    </div>
  </div>
</template>

<script lang="ts">
import Studycodemodel from "../../../mysql_interface/studycodemodel";
import { computed, defineComponent, onMounted, reactive } from "vue";
import { useStore } from "vuex";
import { asyncaddteamlog, asyncdelnotice, asyncgetmynotice } from "../../../api/index";
import { useRoute, useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import { Storekey } from "../../../interface";
export default defineComponent({
  props: ["ID"],
  setup(p) {
    const data = reactive<Studycodemodel.Inotice>({});
    const router = useRouter();
    const query = computed(() => {
      return route.query as { teamid?: string };
    });
    const route = useRoute();
    const store = useStore(Storekey);
    const user = computed<Studycodemodel.Iuser>(() => {
      return store.getters.getuser;
    });
    async function start() {
      if (p.ID && query.value.teamid) {
        const { rows } = await asyncgetmynotice({
          noticeid: p.ID,
        });
        if (rows.length) {
          Object.assign(data, rows[0].notice);
        }
      }
    }
    onMounted(() => {
      start();
    });
    async function click(type: boolean) {
      if (query.value.teamid) {
        const n = type ? "申请" : "拒绝";
        await asyncaddteamlog({
          teamid: Number(query.value.teamid),
          userid: user.value.ID,
          type: n,
        });

        if (data.ID) {
          // await asyncdelnotice({ ID: data.ID });
          await store.dispatch("actionmynotice");
        }
        if (type) {
          ElMessage.success("加入成功");
          router.push({
            name: "团队",
            params: {
              ID: query.value.teamid,
            },
          });
        } else {
          ElMessage.info("已拒绝");
          router.push("/");
        }
      }
    }
    return {
      data,
      click,
    };
  },
});
</script>


<style scoped>
.p-40 {
  padding-top: 40px;
  padding-bottom: 40px;
}
</style>
